
package com.shop.cloud.mall.admin.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.shop.cloud.common.core.util.R;
import com.shop.cloud.common.log.annotation.SysLog;
import com.shop.cloud.mall.common.entity.BalanceConfig;
import com.shop.cloud.mall.admin.service.BalanceConfigService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 余额功能配置
 *
 * @author
 * @date 2023-11-01 10:37:44
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/balanceconfig")
@Tag(description = "balanceconfig", name = "余额功能配置管理")
public class BalanceConfigController {

    private final BalanceConfigService balanceConfigService;

    /**
     * 余额功能配置查询
     * @return R
     */
    @Operation(summary = "余额功能配置查询")
    @GetMapping
    @PreAuthorize("@ato.hasAuthority('mall:balanceconfig:get')")
    public R get() {
        return R.ok(balanceConfigService.getOne(Wrappers.emptyWrapper()));
    }

    /**
     * 余额功能配置修改/新增
     * @param balanceConfig 余额功能配置
     * @return R
     */
    @Operation(summary = "余额功能配置修改/新增")
    @SysLog("修改余额功能配置/新增")
    @PutMapping
    @PreAuthorize("@ato.hasAuthority('mall:balanceconfig:edit')")
    public R updateById(@RequestBody BalanceConfig balanceConfig) {
        if(StrUtil.isBlank(balanceConfig.getId())){
            balanceConfigService.save(balanceConfig);
        }else{
            balanceConfigService.updateById(balanceConfig);
        }
        return R.ok(balanceConfig);
    }
}
